package com.ruoyi.web.core.config.websocket;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import javax.websocket.server.ServerEndpointConfig.Configurator;

/**
 *
 */
public class GetHttpSessionConfigurator extends Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
        System.out.println("调用modifyHandshake方法...");
        HttpSession httpSession = (HttpSession) request.getHttpSession();//session有可能为空
        if (httpSession != null) {
            System.out.println("获取到session id:" + httpSession.getId());
            config.getUserProperties().put(HttpSession.class.getName(), httpSession);
        } else {
            System.out.println("modifyHandshake 获取到null session");
        }
    }
}
